package Day10练习;
//求数组最大值与最小值的差值 打印

public class KaoShi02 {
    public static void main(String[] args) {
        int[] arr = {6,1,7,3,9};

        int i = getsub(arr);
        System.out.println(i);
    }

    public static int getsub (int[] arr){
        int max = arr[0];
        int min = arr[0];
        //遍历最大值
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]){
                max = arr[i];
            }
        }
        //遍历最小值
        for (int i = 0; i < arr.length; i++) {
            if (min > arr[i]){
                min = arr[i];
            }
        }
        int x = max - min;
        return x; //返回最大值-最小值
    }
}
